from lib.ZButton import ZButton
from lib.res.fun import _create_sound
from lib.res.glo import SRC
from addon.Fade.FadeOut import FadeOut


class ItemBtn ( ZButton ) :
	def __init__ ( self , father , surface_in , surface_out , item ) :
		super ( ItemBtn , self ).__init__ ( father , surface_in , surface_out )
		self.item = item
		self.clicksound = _create_sound ( SRC [ 'sound' ] [ 'item' ] )
		self.pa = 10
		self.current = 0
		self.speed = 1

	def draw ( self ) :
		super ( ItemBtn , self ).draw ( )
		if self.current <= self.pa :
			self.current += self.speed

	def _action ( self ) :
		if self.current > self.pa :
			if self.item.type == 0 :
				from resource.ui.sces import players
				if players [ 0 ]._have_item ( 1 ) >= 1 :
					players [ 0 ]._use_item ( 1 )
					from resource.ui.sces import GameScene
					FadeOut ( self.father.father.father , GameScene ( ) )
			else :
				self._running = False
				self.clicksound.play ( )
				from resource.ui.sces import players
				players [ 0 ]._get_item ( int ( self.item.id ) , int ( self.item.type ) , int ( self.item.effect ) )
				self.father.type = 0
